<!DOCTYPE html>
<html>

<div th:replace="common/jsCssRef :: jsfJsCssRef"></div>

<body class="bgf6">

<div th:replace="common/head :: jsfHeader"></div>

<div class="main-body pb100">
    <div class="container pt10">
        <div class="dflx sbt">

            <div th:replace="common/left :: jsfLeft"></div>

            <div class="body-right">
                <div class="bread-nav bgff">
                    <ul class="dflx">
                        <li><a href="###">首页</a></li>
                        <li><a href="###">统筹规划</a></li>
                        <li><a href="">专项发展规划</a></li>
                    </ul>
                </div>

                <div class="bgff mt10" id="app">
                    <div class="wrap">
                        <!--筛选条件/操作-->
                        <div class="row">
                            <div class="col-md-4">
                                <input type="text" id="planNumber" class="form-control" placeholder="请输入规划名称">
                            </div>
                            <div class="col-md-4">
                                <select class="form-control c999" id="originUnit">
                                    <option disabled selected value="">请选择编制单位</option>
                                    <option value="1">长沙</option>
                                    <option value="2">武汉</option>
                                    <option value="3">南京</option>
                                    <option value="4">上海</option>
                                </select>
                            </div>
                            <div class="col-md-4">
                                <div class="input-group">
                                    <input type="text" class="form-control" placeholder="请选择编制时间" id="datepicker">
                                </div>
                            </div>

                        </div>

                        <div class="row mt15">
                            <div class="col-md-4">
                                <select class="form-control c999" id="planStatus">
                                    <option value='' disabled selected class='none'>请选择规划状态</option>
                                    <option value="1">草稿</option>
                                    <option value="2">待审核</option>
                                    <option value="3">审核通过</option>
                                    <option value="4">审核未通过</option>
                                </select>
                            </div>
                            <div class="col-md-4 col-md-offset-4 tr">
                                <button type="button" class="btn btn-primary f12" @click="loadPlanList()"> 查询</button>
                                <button type="button" class="btn btn-white f12" onclick="resetParam()"> 重置</button>
                            </div>
                        </div>

                        <div class="mt30 dflx sbt">
                            <button type="button" class="btn btn-primary f12" onclick="toSpecialAdd()"> 新增专项发展规划
                            </button>
                            <div class="">
                                <button type="button" class="btn btn-white f12"> 批量导入</button>
                                <button type="button" class="btn btn-white f12" @click="batchDelete"> 批量删除</button>
                            </div>
                        </div>

                        <!--表格部分-->
                        <table class="table th52 f14 table-bordered mt20 table-hover" id="cityPlanTable">
                            <template>
                                <el-table
                                        ref="multipleTable"
                                        :data="plans"
                                        tooltip-effect="dark"
                                        style="width: 100%"
                                        @selection-change="handleSelectionChange">

                                    <el-table-column
                                            type="selection"
                                            width="55">
                                    </el-table-column>
                                    <el-table-column
                                            type="index"
                                            label="序号"
                                            width="60">
                                    </el-table-column>
                                    <el-table-column
                                            prop="planName"
                                            label="规划名称"
                                            width="150">
                                    </el-table-column>
                                    <el-table-column
                                            prop="planNo"
                                            label="规划编号"
                                            width="150">
                                    </el-table-column>
                                    <el-table-column
                                            label="编制时间"
                                            :formatter="sliceTime"
                                            width="120">
                                    </el-table-column>
                                    <el-table-column
                                            prop="compileUnit"
                                            label="编制单位"
                                            width="120">
                                    </el-table-column>
                                    <el-table-column
                                            label="当前状态"
                                            width="120">
                                        <template slot-scope="scope"><i
                                                v-bind:class="[scope.row.currentState == 1 ? 'org' : 'gre', 'fa', 'fa-circle']"></i>
                                            {{ planStatus(scope.row.currentState) }}
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="操作">
                                        <template slot-scope="scope">
                                            <el-link type="primary"
                                                     :href="'/view/toSpecialPlanDetail?id=' + scope.row.planId">查看
                                            </el-link>
                                            <el-link type="primary"
                                                     :href="'/view/toSpecialPlanEdit?id=' + scope.row.planId">编辑
                                            </el-link>
                                            <el-link type="primary" @click="delPlan(scope.row.planId)">删除</el-link>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </template>
                        </table>

                        <!--表格尾部-->
                        <div class="dflx aic sbt pb20">
                            <el-pagination
                                    @size-change="handleSizeChange"
                                    @current-change="handleCurrentChange"
                                    :current-page="currentPage"
                                    :page-sizes="[2, 3, 4]"
                                    :page-size="2"
                                    layout="total, sizes, prev, pager, next, jumper"
                                    :total="totalPage">
                            </el-pagination>
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">


    $(".table input[type=checkbox]").change(function () {
        var stat = $(this).prop('checked');
        if (stat) {
            $(this).parents("tr").addClass("selected");
        } else {
            $(this).parents("tr").removeClass("selected");
        }
    });

    $('#special').addClass('active');

    var statusPlanObj = {
        '1': '草稿',
        '2': '待审核',
        '3': '审定通过',
        '4': '审定不通过'
    }


    function resetParam() {
        $("#planNumber").val("")
        $("#datepicker").val("")
        document.getElementById("planStatus").options[0].selected = true;
        document.getElementById("originUnit").options[0].selected = true;
    }

    function toSpecialAdd() {
        window.location.href = contentPath + '/view/toSpecialAdd';
    }

    var appPage = new Vue({
        el: '#app',
        data: {
            plans: [],
            multipleSelection: [],
            currentPage: 1,
            totalPage: 1,
            pageSize: 2
        },
        created: function () {
            this.loadPlanList();
        },
        computed: {},
        methods: {
            sliceTime(row, column) {
                return row.compileTime.slice(0, 10);
            },
            loadPlanList: function () {
                let that = this;
                $.ajax({
                    'url': contentPath + '/specialPlan/getList',
                    'dataType': 'json',
                    'type': 'get',
                    'data': {
                        pageSize: that.pageSize,   //页面大小originUnit
                        pageNumber: that.currentPage,//页码
                        planName: $("#planNumber").val(),
                        compileUnit: $('#originUnit option:selected').val(),
                        compileTime: $("#datepicker").val(),
                        currentState: $('#planStatus option:selected').val()
                    },
                    'success': function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }

                        appPage.plans = result.data.records;
                        appPage.totalPage = result.data.total;
                    },
                    'error': function (result) {
                    }
                });
            },
            handleSelectionChange: function (val) {
                this.multipleSelection = val;
            },

            planStatus: function (val) {
                return statusPlanObj[val];
            },

            handleSizeChange: function (val) {
                this.pageSize = val;
                this.loadPlanList();
            },

            handleCurrentChange: function (val) {
                this.currentPage = val;
                this.loadPlanList();
            },

            delPlan: function (val) {
                this.$confirm('此操作将永久删除该项目, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    delPlanSign(val);
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //批量删除
            batchDelete() {
                let selectedList = this.$refs.multipleTable.selection;
                if(selectedList.length==0){
                    return;
                }
                this.$confirm('此操作将永久删除这些项目, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let ids = "";
					selectedList.forEach(item=>{
						ids+=item.planId+",";
					});
					ids = ids.substring(0, ids.length - 1);
					deleteAll(ids);
				});
            }
        }
    })


	function delPlanSign(planId) {
		$.ajax({
			'url': contentPath + '/specialPlan/delete',
			'dataType': 'json',
			'type': 'get',
			'data': {
				'planId': planId
			},
			'success': function (result) {
				if (result.code != 1000) {
					alert(result.message);
					return;
				}

				window.location.reload();
			},
			'error': function (result) {
			}
		});
	}

	//批量删除
	function deleteAll(ids) {
		$.ajax({
			'url': contentPath + '/specialPlan/deleteList',
			'dataType': 'json',
			'type': 'post',
			'data': {
				'ids': ids
			},
			'success': function (result) {
				if (result.code != 1000) {
					alert(result.message);
					return;
				}
				window.location.reload();
			},
			'error': function (result) {
			}
		});
	}

    $('#datepicker').fdatepicker({
        format: 'yyyy-mm-dd',
    });


</script>
</body>
</html>
